<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><!-- bootstrap依赖 -->
<title>DEMO_编辑页面</title>
<jsp:include page="/css/includeCSS.jsp">
	<jsp:param value="validator,datetime,fileinput,formJ" name="csses"/>
</jsp:include>
</head>
<body>
	<div id="bodyTopDiv" style="margin-top: 20px;">
		<span class="label label-info">DEMO</span>
		<div style="padding: 0px 1% 15px; float: right;">
			<button class="btn btn-info btn-sm" onclick="submitForm()"
				id="submitButton">保存</button>
			<button class="btn btn-info btn-sm" onclick="deleteForm()"
				style="display: none;" id="deleteButton">删除</button>
			<button class="btn btn-info btn-sm" onclick="back()" id="backButton">关闭</button>
		</div>
	</div>
	<div class="container-fluid" style="margin-top:30px;">
		<form id="jangleEditForm" name="jangleEditForm" class="form-horizontal">
			<div class="form-group" >
				<label for="name" class="col-md-4 control-label">名称：</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="name" name="name" placeholder="请输入名称">
				</div>
				<label for="age" class="col-md-1 control-label">年龄：</label>
				<div class="col-md-2">
					<input type="text" class="form-control" id="age" name="age" placeholder="请输入年龄">
				</div>
			</div>
			<div class="form-group" >
				<label for="time" class="col-md-4 control-label">时间：</label>
				<div class="input-group date form_date col-md-5" style="padding-left:15px;padding-right:15px;" data-date-format="yyyy-mm-dd" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
                    <input id="time" name="time"  class="form-control" size="16" type="text" value="" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
					<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
			</div>
			<div class="form-group" >
				<label for="extends1" class="col-md-4 control-label">拓展字段1：</label>
				<div class="col-md-5">
					<input type="text" class="form-control" id="extends1" name="extends1" placeholder="请输入拓展字段1">
				</div>
			</div>
			<div class="form-group" >
				<label for="dmDesc7" class="col-md-4 control-label">描述7：</label>
				<div class="col-md-5">
					<input type="text" class="form-control" id="dmDesc7" name="dmDesc7" placeholder="请输入描述7">
				</div>
			</div>
			<div class="form-group" >
				<label for="dmDesc8" class="col-md-4 control-label">描述8：</label>
				<div class="col-md-5">
					<input type="text" class="form-control" id="dmDesc8" name="dmDesc8" placeholder="请输入描述8">
				</div>
			</div>
			<div class="form-group" >
				<label for="jAttFile" class="col-md-4 control-label">文件：</label>
				<div class="col-md-5">
					<div id="attListJ" style="display:inline-block" ></div>
					<input type="file" name="file" id="jAttFile"  multiple="multiple" data-show-caption="true">
				</div>
			</div>
			<input type="hidden" name="id" id="id">	<!-- 主键ID隐藏域 -->
			<input type="hidden" name="status" id="status" value="1">	<!-- 状态隐藏域 -->
		</form>
	</div>
	<jsp:include page="/js/includeJS.jsp">
		<jsp:param value="validator,datetime,fileinput,utilJ" name="jses"/>
	</jsp:include>
	<script type="text/javascript" src="js/demoEdit.js?v=202311030912"></script>
	<script type="text/javascript">
		var fileInputParam = {}; //附件上传的拓展参数
		var extArray = null; //扩展名
		var fileInputId = "jAttFile";
		// 提交表单
		function submitForm() {
			$("#jangleEditForm").data("bootstrapValidator").validate(); //提交验证写法1
			var valid = $("#jangleEditForm").data("bootstrapValidator")
					.isValid(); //验证通过返回true 不通过false
			if (!valid) {
				alert("请完善信息");
				return;
			}
			$.ajax({
				type:"POST",
				url : "/demoCtrl2/insert.ctrl",
				dataType : "json",
				cache:false,
				data : $("#jangleEditForm").serialize(),
				error : function(request, textStatus, errorThrown) {
					jangleShowAjaxError(request, textStatus, errorThrown);
				},
				success : function(data) {
// 					success(data);		//执行成功后的判断，操作成功则返回列表页。
					//存在附件时的判断start ************
					if (data == null || data.code == null) {
						hideMask();
						alert("异常操作，请联系管理员");
						return;
					}
					if (data != null && data.code == 10001) {
						var file = $("#"+fileInputId).val();
						if (file == null || file == "") {
							hideMask();
							success(data);
							return;
						}
						//存在附件则上传附件
						fileInputParam["attSourceId"] = data.model.id; //业务主键id
						fileInputParam["attSourceType"] = "demo"; //填业务表名称
						fileUploadJ(fileInputId); //上传附件
					} else {
						hideMask();
// 						alert(data.rm.msg);
						alert(data.message);
						return;
					}
					//存在附件时的判断end ************
				}
			});
		}
		// 删除记录
		function deleteForm() {
			if (confirm("确定删除此记录吗？")) {
				$.ajax({
					type:"POST",
					url : "/demoCtrl2/deleteByPrimaryKey.ctrl",
					dataType : "json",
					cache : false,
					data : {
						"id" : $("#id").val()
					},
					error : function(request, textStatus, errorThrown) {
						jangleShowAjaxError(request, textStatus, errorThrown);
					},
					success : function(data) {
						success(data);
					}
				});
			}
		}

		// dom加载完成之后
		$(function() {
			// 初始化日期控件
			$('.form_date').datetimepicker({
		        language:  'zh-CN',
		        format: 'yyyy-mm-dd 00:00:00',
// 		        format: 'yyyy-mm-dd HH:mm:ss',
		        weekStart: 1,
		        todayBtn:  1,
				autoclose: 1,
				todayHighlight: 1,
				startView: 2,
				minView: 2,
				forceParse: 0
		    });
			// 初始化附件上传组件
			initFileInput(fileInputId, "", fileInputParam, extArray);
			
			//TODO 这里添加其余逻辑
			if (!ps["id"]){
				return;
			}
			$.ajax({
				url : "/demoCtrl2/selectByPrimaryKey.ctrl",
				dataType : "json",
				cache : false,
				data : {
					"id" : ps["id"]
				},
				error : function(request, textStatus, errorThrown) {
					jangleShowAjaxError(request, textStatus, errorThrown);
				},
				success : function(data) {
					if (data != null && data.code == "10001"
							&& data.model != null) {
						for ( var item in data.model) {
							$("#" + item).val(data.model[item]);
						}
						$("#deleteButton").show(); // 显示删除按钮
					}
				}
			});
			// 加载附件
			loadAttachmentJ(ps["id"],"demo",true);
		})
	</script>
</body>
</html>